<?php 
/**
 * 备份还原控制器
 */
class BackupController extends AuthController{
    /**
     * 显示备份列表
     */
    public function index(){
		//获得所有目录
        $dirs = Dir::tree('Backup');
		$this->assign('dirs',$dirs);
		$this->display();
    }
	
	/**
	 * 备份
	 */
	public function backup(){
	    $result = Backup::backup(
			array(
				'size' => 200,// 分卷大小
				'dir' => 'Backup/'.date("Ymdhis").'/',// 备份目录
				'step_time' => 1,// 备份时间间隔
			)
		);
		if($result === FALSE){
			// 备份发生错误
			$this->error(Backup::$error, U('index'));
		}else{
			if($result['status'] == 'success'){
				//备份完成
				$this->success($result['message'], U('index'));
			}else{
				// 备份过程中
				$this->success($result['message'], $result['url'], 0.2);
			}
		}
	}
	
	/**
	 * 还原
	 */
	public function recovery(){
		//备份目录
	    $dir = Q('post.dir');
		//如果session里面没有dir，证明是第一次存储
		if(!isset($_SESSION['dir'])){
			$_SESSION['dir'] = $dir;
		}
		$result = Backup::recovery(array('dir' => $_SESSION['dir']));
		if($result === false){// 还原发生错误
			$this->error(Backup::$error, U('index'));
		}else{
			if($result['status'] == 'success'){
				// 还原完毕
				unset($_SESSION['dir']);
				$this->success($result['message'],U('index'));
			}else{
				// 还原运行中 ...
				$this->success($result['message'],$result['url'],0.2);
			}
		}
	}
	
	
	
	
	
 }
 
 
 
 
 
 
 
 
 
 
 























 ?>